package com.tjbklx1.zk.testzkclient;

import org.I0Itec.zkclient.IZkDataListener;
import org.I0Itec.zkclient.ZkClient;
import org.I0Itec.zkclient.serialize.BytesPushThroughSerializer;

public class SubscribeDataChanges {

	private static class ZkDataListener implements IZkDataListener {

		public void handleDataChange(String dataPath, Object data) throws Exception {
			System.out.println(dataPath + ":" + data.toString());
		}

		public void handleDataDeleted(String dataPath) throws Exception {
			System.out.println(dataPath);
		}

	}

	public static void main(String[] args) throws InterruptedException {
		ZkClient zc = new ZkClient("127.0.0.1:2181", 10000, 10000, new BytesPushThroughSerializer());
		System.out.println("conneted ok!");
		zc.subscribeDataChanges("/cli", new ZkDataListener());
		Thread.sleep(Integer.MAX_VALUE);
	}

}